package sk.vasicek.drinkmanager.domain;

import java.math.BigInteger;

import android.content.Context;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class DrinkUI {

	Integer labelText;
	String buttonText;
	Integer buttonId;
	Integer priceId;
	Integer labelId;
	Integer countId;
	Button button;
	EditText price;
	TextView label;
	TextView count;

	CustomDrink customDrink;

	public DrinkUI(Integer buttonText, String buttonId, String priceId, String labelId, String countId) {
		this.labelText = buttonText;
		this.buttonText = "";
		this.buttonId = toHexString(buttonId);
		this.priceId = toHexString(priceId);
		this.labelId = toHexString(labelId);
		this.countId = toHexString(countId);
	}

	public DrinkUI(String buttonText, String buttonId, String priceId, String labelId, String countId) {
		this.labelText = -1;
		this.buttonText = buttonText;
		this.buttonId = toHexString(buttonId);
		this.priceId = toHexString(priceId);
		this.labelId = toHexString(labelId);
		this.countId = toHexString(countId);
	}

	public void setButton(Button button) {
		this.button = button;
	}

	public void setCount(TextView count) {
		this.count = count;
	}

	public void setLabel(TextView label) {
		this.label = label;
	}

	public void setPrice(EditText price) {
		this.price = price;
	}

	/**
	 * @return the buttonText
	 */
	public String getButtonText() {
		return buttonText;
	}

	/**
	 * @param buttonText
	 *            the buttonText to set
	 */
	public void setButtonText(String buttonText) {
		this.buttonText = buttonText;
	}

	/**
	 * @return the labelText
	 */
	public Integer getLabelText() {
		return labelText;
	}

	/**
	 * @return the button
	 */
	public Button getButton() {
		return button;
	}

	/**
	 * @return the price
	 */
	public EditText getPrice() {
		return price;
	}

	/**
	 * @return the label
	 */
	public TextView getLabel() {
		return label;
	}

	/**
	 * @return the count
	 */
	public TextView getCount() {
		return count;
	}

	public void setCustomDrink(CustomDrink customDrink) {
		this.customDrink = customDrink;
	}

	public CustomDrink getCustomDrink() {
		return customDrink;
	}

	public Integer toHexString(String str) {
		if (str.length() > 4)
			return new BigInteger(1, (str.substring(0, 2) + str.substring(str.length() - 2, str.length())).getBytes()).intValue();
		else
			return new BigInteger(1, str.getBytes()).intValue();
	}

	public String fromHexString(Integer raw) {
		String hex = Integer.toHexString(raw).toUpperCase();
		StringBuilder str = new StringBuilder();
		for (int i = 0; i < hex.length(); i += 2) {
			str.append((char) Integer.parseInt(hex.substring(i, i + 2), 16));
		}
		return str.toString();
	}

	public String getLabelText(Context context) {
		if (labelText == -1)
			return buttonText;
		else
			return context.getResources().getText(labelText).toString();
	}

	public void setLabelText(Integer labelText) {
		this.labelText = labelText;
	}

	public Integer getButtonId() {
		return buttonId;
	}

	public void setButtonId(Integer buttonId) {
		this.buttonId = buttonId;
	}

	public Integer getPriceId() {
		return priceId;
	}

	public void setPriceId(Integer priceId) {
		this.priceId = priceId;
	}

	public Integer getLabelId() {
		return labelId;
	}

	public void setLabelId(Integer labelId) {
		this.labelId = labelId;
	}

	public Integer getCountId() {
		return countId;
	}

	public void setCountId(Integer countId) {
		this.countId = countId;
	}

}
